﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;

namespace Lon.Server
{
  
    public class CSMAlarmQueryProvider : DataProcessProvider
    {
        private FrontServerNode forntServer = null;
        public CSMAlarmQueryProvider(FrontServerNode frontServer)
        {
            this.forntServer = frontServer;
        }
        protected override void ProcessCommandPackage(DataFrame pkg)
        {
            
            MemoryStream ms=new MemoryStream(pkg.DataBuf);
            BinaryReader br=new BinaryReader(ms);
            UInt32 startTime = br.ReadUInt32();
            UInt32 endTime=br.ReadUInt32();
            MemoryStream[] res=DataStoreService.ReadAlarm(pkg.SrcId,startTime,endTime);
            MemoryStream resStream = new MemoryStream();
            BinaryWriter bw=new BinaryWriter(resStream);

            bw.Write((byte)0x42);
            bw.Write((byte)res.Length);
            for (int i = 0; i < res.Length; i++)
            {
                res[i].WriteTo(resStream);
            }
            DataFrame df = new DataFrame(pkg.SrcId, pkg.DstId, DataDir.SeverAck, false, false, false,(byte) pkg.MajorDataType, pkg.MinorDataType, resStream.ToArray());

            this.forntServer.SendMessage(df);
           
        }
    }
}

